<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN" xml:lang="zh_CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../rurple.css" type="text/css" />

<title>指令和规测简要：</title>
</head>
<body>
<h2 class="title">学习Python: 儿童利用RUR-PLE玩游戏！</h2>
<h6>André Roberge, © 2005-2010</h6>
<h3 class="section">指令和规测简要</h3>
<p>乐跑(英文名字为Reeborg)的动作</p>

<pre>
<span class="comment"># 前进</span>
move()
<span class="comment"># 向左走</span>
turn_left()
<span class="comment"># 检报警器</span>
pick_beeper()
<span class="comment"># 放报警器</span>
put_beeper()
<span class="comment"># 关机</span>
turn_off()
</pre>

<p>测试的命令:</p>

<pre>
<span class="comment"># 前面没有东西</span>
front_is_clear()
<span class="comment"># 左面没有东西</span>
left_is_clear()
<span class="comment"># 右面没有东西</span>
right_is_clear()
<span class="comment"># 面向北面</span>
facing_north()
<span class="comment"># 带了报警器</span>
carries_beepers()
<span class="comment"># 到达了报警器所在的位置</span>
on_beeper() <span class="comment"># 等于:</span> next_to_a_beeper()
</pre>

<p>一些特别的本来附带的功能：</p>

<pre>
<span class="comment"># 重覆</span>
repeat(function, number_of_times)
<span class="comment"># 要注意的是这个是等于</span>
<span class="keyword">for</span> number <span class="keyword">in</span> range(number_of_times):
    function()
</pre>

<p>面向对象编程:</p>

<pre>
<span class="comment"># 以下的命令跟上面的解释是一样的，只是现在这些命令只是面向乐跑(Reeborg)而已！</span>
Reeborg = UsedRobot()
Reeborg.move()
Reeborg.turn_left()
Reeborg.pick_beeper()
Reeborg.put_beeper()
Reeborg.front_is_clear()
Reeborg.left_is_clear()
Reeborg.right_is_clear()
Reeborg.facing_north()
Reeborg.carries_beepers()
Reeborg.on_beeper() <span class="comment"># 等于:</span> Reeborg.next_to_a_beeper()
</pre>

<p>高级选项:</p>

<pre>
set_trace_style(style=1, colour=<span class="string">'sea green'</span>)
<span class="comment"># 任何颜色（colour)可被wxPython认可的</span>
<span class="comment"># style为形式，可以选择的是[1, 2, 3, 4, 5]其中一个</span>
set_delay(次数)
<span class="comment"># 0 &lt; 次数 &lt; 10 (秒)</span>

Reeborg = UsedRobot(avenues=1, streets=1, orient_key = <span class="string">'E'</span>,
                 beepers=0, name=<span class="string">'robot'</span>, colour=<span class="string">'grey'</span>)
<span class="comment"># orient_key 是以下其中一个 <span class="string">'E'</span> 或 <span class="string">'e'</span>, <span class="string">'W'</span> 或 <span class="string">'w'</span>, <span class="string">'S'</span> 或 <span class="string">'s'</span>, <span class="string">'N'</span> 或 <span class="string">'n'</span>.</span>

<span class="comment"># 可选择的 <b>机器人</b> 颜色有: <span class="string">'yellow'</span>, 
# <span class="string">'blue'</span>, <span class="string">'light blue'</span>, <span class="string">'purple'</span> 和 <span class="string">'green'</span>.  
# 如果选择了其他颜色将成为默认颜色 (<span class="string">'grey'</span>) 来处理 </span>

<span class="comment"># 需要留意的是一个"serial number"有可能设定一个或多个路径（小道）
# 机器人的"name",每个机器人在整个游戏过程/工作期间
# 跟rur-ple将会有一个独特的名字。</span>

Reeborg.set_trace_style(style=1, colour=<span class="string">'sea green'</span>) 
Reeborg.set_delay(time)
</pre>

<p>新改善以后的机器人！</p>

<pre>
Guido = RefurbishedRobot()  <span class="comment"># 从UsedRobot继承</span>

<span class="comment"># 其它方法:</span>
Guido.turn_right()
Guido.left_clear()
Guido.right_clear()
Guido.facing_east()
Guido.facing_south()
Guido.facing_west()
Guido.roll_dice(n=6) <span class="comment"># 随机整数在1和n之间。</span>
</pre>

<div class="lessons_nav">
<a href="rur.htm"><img alt="home" src=
"../images/home.png" /></a>
</div>
</body>
</html>
